<?php

//@session_id($session_id);
//@session_start();


//var_dump($userid);var_dump($session_id);
define('EmpireCMSAdmin','1');
require_once("../class/connect.php");
require_once("../class/db_sql.php");
require_once("../class/functions.php");
require_once("../class/user.php");
require_once("../class/page_obj.php");
$userid=$lguserid;

define("FILE_PATH",str_replace("\\","/",dirname(dirname(dirname(__FILE__)))).'/');
$link=db_connect();
$empire=new mysqlquery();
$dirPath="tribe_pic/".date("Y_m_d");
$dir=FILE_PATH.$dirPath;
$tribe_id=$_REQUEST['id'];
if($_FILES['Filedata']['size']>1024*1024*2){show_error("请上传2M以下的照片。");}
if($_FILES['Filedata']['error']!=0){show_error("发生系统错误，请与系统管理员联系");}
if(!$userid){show_error("用户未登录，不能添加照片！");}
if(!$tribe_id){show_error("id获取错误！");}
$info=pathinfo($_FILES['Filedata']['name']);
$extName=strtolower($info['extension']);
$fileName=str_replace(".{$info['extension']}","",$info['basename']);
$md5Str=md5(uniqid(microtime()));
$newName="tribe_{$tribe_id}_$md5Str.".$extName;
if(!in_array($extName,array("gif","jpg","png"))){show_error("系统只能支持gif、jpg、png图片！");}
if(!is_dir($dir)){
	@mkdir($dir);
	@chmod($dir,'755');
}else{}
if(move_uploaded_file($_FILES["Filedata"]["tmp_name"],$dir."/".$newName)){
	$db="phome_ecms_tribe";
	$act_id=$_REQUEST['act_id'];
	$arr=array("cover_url"=>$dirPath."/".$newName."");	
	
	DbEdit($db,$arr,array("userid"=>$userid,"id"=>$tribe_id,'userid'=>$userid));
	getPics($dir."/".$newName,array("119_105"),0);
	show_succ('ok');
}else{
	show_error("移动文件时，发生系统错误！");
}
die(json_encode($arr));

?>